﻿using System.ServiceModel;
using System.ServiceModel.Activation;

using SBPweb.PROvibe.Shared.Library.Components;
using SBPweb.PROvibe.Server.Library.Services;

using SBPweb.PROvibe.Server.Modules.ContentProvider.Contracts;

namespace SBPweb.PROvibe.Server.Modules.ContentProvider
{

    [ServiceBehavior(Name = "IContentProviderService", Namespace = Contracts.Constants.Services.ContentProviderNamespace)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ContentProviderService : ServiceBase<IContentProviderService>, IContentProviderService
    {

        #region Fields

        #endregion

        #region Constructor logic

        public ContentProviderService()
            : this(null)
        {
        }

        public ContentProviderService(IModule parentModule)
            : base(parentModule)
        {
        }

        #endregion

        #region Properties

        public override string Name
        {
            get
            {
                return "ContentProviderService.MOSS14";
            }
        }
        
        #endregion

        #region Operations

        [OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
        public void DoFoo()
        {
            Microsoft.SharePoint.Client.ClientContext context = new Microsoft.SharePoint.Client.ClientContext("http://cerberus");
            context.Load(context.Web);
        }

        #endregion

        #region Methods

        protected override void OnInitialize()
        {
            //LayoutProvider = new LayoutProviderService();
            //ComponentProvider = new ComponentProviderService();

            //ServiceProvider.Contracts.IServiceProviderService isps = ParentModule.PublicServices.FirstByType<ServiceProvider.Contracts.IServiceProviderService>();
            //ServiceHost host1 = isps.CreateServiceHost<LayoutProviderService, ILayoutProviderService>(Parent, "LayoutProvider.svc");
            //ServiceHost host2 = isps.CreateServiceHost<ComponentProviderService, IComponentProviderService>(Parent, "ComponentProvider.svc");

            //DataProvider.Contracts.IDataProviderService idps = ParentModule.PublicServices.FirstByType<DataProvider.Contracts.IDataProviderService>();
            //idps.CreateConnection("PROvibe");
        }

        protected override void OnTerminate()
        {
        }
                
        #endregion
        
    }

}